package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.common.anno.OperLog;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.sys.SysOperLog;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "商品品牌管理模块")
@RequestMapping("/admin/product/brand")
public class BrandController {
    @Resource
    BrandService brandService;
    @Operation(summary = "查询所有品牌")
    @GetMapping("findAll")
    public Result findAll(){
        List<Brand> list =  brandService.findAll();
        return Result.ok().data(list);
    }
    @OperLog(title = "品牌管理-分页查询")
    @Operation(summary = "分页查询品牌")
    @GetMapping("page/{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize")Integer pageSize){
        PageInfo<Brand> pageInfo =  brandService.page(pageNum,pageSize);
        return Result.ok().data(pageInfo);
    }
    @OperLog(title = "品牌管理-删除品牌",businessType = 3 , isSaveResponseData = false)
    @Operation(summary = "删除品牌")
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id")Long id){
        brandService.deleteById(id);
        return Result.ok();
    }
    @Operation(summary = "根据id查询品牌")
    @DeleteMapping("getById/{id}")
    public Result getById(@PathVariable("id")Long id){
        Brand brand = brandService.getById(id);
        return Result.ok().data(brand);
    }
    @Operation(summary = "更新品牌")
    @PutMapping("updateById")
    public Result updateById(@RequestBody Brand brand){
        brandService.updateById(brand);
        return Result.ok();
    }

    @Operation(summary = "新增品牌")
    @PostMapping("save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.ok();
    }


}
